﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using usedcartrade.DataAccessLayer;
using usedcartrade.Models;

namespace usedcartrade.Controllers
{
    public class SubscribeInfoesController : Controller
    {
        private UsedCarERPDAL db = new UsedCarERPDAL();

        // GET: SubscribeInfoes
        public ActionResult Index()
        {
            var subscribeinfos = db.subscribeinfos.Include(s => s.user);
            return View(subscribeinfos.ToList());
        }

        // GET: SubscribeInfoes/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            SubscribeInfo subscribeInfo = db.subscribeinfos.Find(id);
            if (subscribeInfo == null)
            {
                return HttpNotFound();
            }
            return View(subscribeInfo);
        }

        // GET: SubscribeInfoes/Create
        public ActionResult Create()
        {
            ViewBag.UserID = new SelectList(db.users, "ID", "ID");
            return View();
        }

        // POST: SubscribeInfoes/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "ID,CarID,SubPhone,SubName,SubEmail,UserID")] SubscribeInfo subscribeInfo)
        {
            if (ModelState.IsValid)
            {
                db.subscribeinfos.Add(subscribeInfo);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.UserID = new SelectList(db.users, "ID", "ID", subscribeInfo.UserID);
            return View(subscribeInfo);
        }

        // GET: SubscribeInfoes/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            SubscribeInfo subscribeInfo = db.subscribeinfos.Find(id);
            if (subscribeInfo == null)
            {
                return HttpNotFound();
            }
            ViewBag.UserID = new SelectList(db.users, "ID", "ID", subscribeInfo.UserID);
            return View(subscribeInfo);
        }

        // POST: SubscribeInfoes/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "ID,CarID,SubPhone,SubName,SubEmail,UserID")] SubscribeInfo subscribeInfo)
        {
            if (ModelState.IsValid)
            {
                db.Entry(subscribeInfo).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.UserID = new SelectList(db.users, "ID", "ID", subscribeInfo.UserID);
            return View(subscribeInfo);
        }

        // GET: SubscribeInfoes/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            SubscribeInfo subscribeInfo = db.subscribeinfos.Find(id);
            if (subscribeInfo == null)
            {
                return HttpNotFound();
            }
            return View(subscribeInfo);
        }

        // POST: SubscribeInfoes/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            SubscribeInfo subscribeInfo = db.subscribeinfos.Find(id);
            db.subscribeinfos.Remove(subscribeInfo);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
